<template>
  <div>
    <div class="card">
      <div class="login-card">
        <div class="title">
          <span>三微</span>
        </div>
        <div class="ipt">
          <div class="user-name">
            <span>账号：</span>
            <input type="text" v-model="username" placeholder="请输入账号" />
          </div>
          <div class="password">
            <span>密码：</span>
            <input
              type="password"
              v-model="password"
              placeholder="请输入密码"
            />
          </div>
          <button @click="goLogin">登录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      username: "张三",
      password: "abc12345678",
    };
  },
  methods: {
    async goLogin() {
      let self = this;
      let username = self.username;
      let password = self.password;
      sessionStorage.setItem("username", username);
      sessionStorage.setItem("password", password);
      const res = await self.$post("/login", {
        username: username,
        password: password,
      });
      console.log(res);
      let token = res.result.token;
      let role_id = res.result.user_info.role_id;
      let id = res.result.user_info.id;
      sessionStorage.setItem("token", token);
      sessionStorage.setItem("role_id", role_id);
      sessionStorage.setItem("id", id);
      self.$router.push("/Home");
    },
  },
};
</script>

<style lang="scss">
$blue-text: #5997fe;
.card {
  width: 450px;
  height: 350px;
  //   border: 1px solid pink;
  position: relative;
  top: 50%;
  left: 50%;
  transform: translate(-50%, 50%);
  background: #fff;
  box-shadow: 0 0 50px 2px #e1e6fa;
  border-radius: 7px;
}
.login-card {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
  padding: 20px 40px;
  .title {
    color: $blue-text;
    font-size: 20px;
    text-align: center;
    font-weight: bold;
  }
  .ipt {
    margin: 40px 0;
    text-align: center;
    input {
      height: 50px;
      border: none;
      background: #f3f6ff;
      border-radius: 7px;
      padding: 0 0 0 10px;
      width: 250px;
      margin-left: 10px;
      &:focus {
        // box-sizing: border-box;
        outline: 0px;
        border: 1px solid $blue-text;
      }
    }
    .password {
      margin-top: 30px;
    }
    button {
      background: $blue-text;
      color: #fff;
      border: none;
      width: 100%;
      height: 50px;
      font-size: 18px;
      width: 260px;
      border-radius: 10px;
      margin-top: 30px;
    }
  }
}
</style>